package com.hj.controller;

import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.hj.Tools.MD5;
import com.hj.domain.Studentinfo;
import com.hj.service.inter.StudentServiceInter;

@Controller
public class LoginController {

	@Autowired
	private StudentServiceInter studentServiceInter;
	
	//用户登录
	@RequestMapping(value="/login",method=RequestMethod.POST)
	public String login(@RequestParam("username") String username,@RequestParam("password") String password,
			HttpServletRequest request) throws Exception {
		HttpSession session = request.getSession();
		session.setAttribute("username",username);
	    HashMap<String, Object> studentMap = new HashMap<String, Object>();
	    studentMap.put("username",username.trim());
	    studentMap.put("password",MD5.toMD5(password.trim()));
	    List<Studentinfo> list=studentServiceInter.getOnlyUser(studentMap);
	    session.setAttribute("userinfo", list);
	    //登录成功，进入下一个页面
	    return "";	    
	 }
	//用户注销
	@RequestMapping("/logout")
	public String logout(HttpSession session)throws Exception{
		session.invalidate();
		//返回首页
		return "";
	}
}
